package org.example.myleet.p773;

import org.example.myleet.Utils.Assert;
import org.example.myleet.Utils.JsonUtils;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        Solution solution = new Solution();
        Assert.isTrue(1 == solution.slidingPuzzle(parseBoard("[[1,2,3],[4,0,5]]")));
        Assert.isTrue(-1 == solution.slidingPuzzle(parseBoard("[[1,2,3],[5,4,0]]")));
        Assert.isTrue(5 == solution.slidingPuzzle(parseBoard("[[4,1,2],[5,0,3]]")));
        Assert.isTrue(14 == solution.slidingPuzzle(parseBoard("[[3,2,4],[1,5,0]]")));
        Assert.isTrue(-1 == solution.slidingPuzzle(parseBoard("[[3,4,2],[1,5,0]]")));
    }

    private static int[][] parseBoard(String input) {
        List<List<Integer>> parsedLists = JsonUtils.parse(input, List.class);
        int[][] board = new int[parsedLists.size()][parsedLists.get(0).size()];
        int i = 0;
        for (List<Integer> list : parsedLists) {
            int j = 0;
            for (Integer integer : list) {
                board[i][j++] = integer;
            }
            ++i;
        }
        return board;
    }
}
